package com.ruifu.proj.controller;

import com.fhzncloud.cloud.common.core.util.R;
import com.ruifu.common.po.PmPtCondTask;
import com.ruifu.common.utils.BeanConverter;
import com.ruifu.proj.dto.ptcondtask.PmPtCondTaskDTO;
import com.ruifu.proj.service.PmPtCondTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author nyr
 * @create 2019/8/13
 */
@RestController
@CrossOrigin
@RequestMapping("/pmPtCondTask")
public class PmPtCondTaskController {

    @Autowired
    private PmPtCondTaskService pmPtCondTaskService;


    /**
     * 查询当前任务的启动条件列表
     *
     * @param pcSId     后序任务id
     * @param pcSStatus 后序任务状态
     * @return
     */
    @GetMapping(value = "/findByPcSIdAndPcSStatus")
    public R findByPcSIdAndPcSStatus(Long pcSId, String pcSStatus) {
        return pmPtCondTaskService.findByPcSIdAndPcSStatus(pcSId, pcSStatus);
    }

    /**
     * 批量添加任务启动条件
     *
     * @param pmPtCondTaskDTOList
     * @return
     */
    @PostMapping(value = "/batchInsert")
    public R batchInsert(@RequestBody List<PmPtCondTaskDTO> pmPtCondTaskDTOList) {
        try {
            return R.ok(pmPtCondTaskService.saveBatch(BeanConverter.copyList(pmPtCondTaskDTOList, PmPtCondTask.class)));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        }
    }

    /**
     * 批量删除任务启动条件
     *
     * @param pcIds id数组
     * @return
     */
    @PostMapping(value = "/batchDelete")
    public R batchDelete(@RequestBody List<Long> pcIds) {
        try {
            return R.ok(pmPtCondTaskService.removeByIds(pcIds));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        }
    }
}
